package com.example.smartcity_poverty.ui.Home.adapter

import android.content.Intent
import android.text.Html
import com.example.smartcity_poverty.App
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.logic.model.NewsModel
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.ui.ShowNewsActivity
import kotlinx.android.synthetic.main.re_item_news.*

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *  新闻列表填充
 **/
@Suppress("DEPRECATION")
class NewsAdapter (
    private val list: MutableList<NewsModel.RowsBean>,
    layoutId: Int
) : BaseRecyclerAdapter<NewsModel.RowsBean>(list, layoutId){
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: NewsModel.RowsBean,
        position: Int,
        holder: BaseViewHolder
    ) {

        // 设置动画
        holder.itemView.animation = App.getAnimationBottomAndTop()

        // 获取数据
        val d = list[position]

        // 将数据填充到UI上
        glide(url + d.cover, holder.viewFind.newsImage)
        holder.viewFind.newsTitle.text = d.title
        holder.viewFind.newsContent.text = Html.fromHtml(d.content)
        holder.viewFind.newsTime.text = d.publishDate

        val si = d.likeNum.toString() + "评论"
        holder.viewFind.newsUserSize.text = si

        val con = holder.viewFind.view?.context
        // 点击查看新闻详情
        holder.itemView.setOnClickListener {
            con?.startActivity(Intent(con, ShowNewsActivity::class.java).apply {
                putExtra("id", d.id.toString())
            })
        }
    }
}